#!/usr/bin/python
#-*- coding: utf-8 -*-
import poplib
import cStringIO
import email
import base64
import string

def recv_mail(usr,pwd):
	M = poplib.POP3('pop3.163.com')
	M.user(usr)
	M.pass_(pwd)
	#numMessages = len(M.list()[1])
	mailCount,size = M.stat();
	#mailCount:number of mails
	#size:size of mails
	if mailCount != 0:
		if mailCount == 1:
			print "There is only 1 mail in the recv box"
		else:
			print "There are",mailCount," mails in the recv box"
		hdr,message,octet = M.retr(1)#receive fist mail
		#hdr  some infromation
		#message  content: all lines
		#octet size
		mail = email.message_from_string(string.join(message,'\n'))
		print "content:",mail.get_payload()
		#print mail.as_string()
	else:
		print "There is nothing"

if __name__ == '__main__':
	recv_mail("lyccode","299792458")
